package cn.tedu.luban.worker.main.controller;

import cn.tedu.luban.worker.main.converter.WorkerConverter;
import cn.tedu.luban.worker.main.service.WorkerService;
import cn.tedu.luban.worker.protocol.VO.FrontWorkerDetailVO;
import cn.tedu.luban.worker.protocol.bo.FrontWorkerBO;
import cn.tedu.luban.worker.protocol.param.AuditSubmitParam;
import cn.tedu.luban.worker.protocol.param.WorkerRegistParam;
import com.tedu.inn.protocol.exception.BusinessException;
import com.tedu.inn.protocol.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class WorkerController {

    @Autowired
    private WorkerService workerService;

    /**
     * 师傅入驻
     */
    @PostMapping("/worker/create")
    public Result<Long> registWorker(@RequestBody WorkerRegistParam workerRegistParam, @RequestHeader("Authorization") String authorization) throws BusinessException {

        log.info("workerRegistParam:{}",workerRegistParam);
        log.info("Auhtorization:{}",authorization);
        //调用业务层，让业务方法接收入参，写数据 返回创建好的workerId
        Long workerId=workerService.registWorker(workerRegistParam);
        return new Result<>(workerId);
    }

    @Autowired
    private WorkerConverter workerConverter;

    @GetMapping("/worker/detail")
    public Result<FrontWorkerDetailVO> detailWorker() throws BusinessException{
        //1.调用业务逻辑查询师傅数据 BO
        FrontWorkerBO frontWorkerBO= workerService.detailWorker();
        //2.转换器将BO转换成VO
        FrontWorkerDetailVO frontWorkerDetailVO = workerConverter.bo2vo(frontWorkerBO);

        return new Result<>(frontWorkerDetailVO);
    }


}
